package 题目集.滑动窗口.ch01_定长窗口;

/**
 * https://leetcode.cn/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/
 * 问你长度为k的字串中，最多有多少满足条件的
 */
public class ch01_定长窗口模板 {
    public int maxVowels(String s, int k) {
        char[] chars = s.toCharArray();
        boolean[] map = new boolean[150];
        map['a'] = true;
        map['e'] = true;
        map['i'] = true;
        map['o'] = true;
        map['u'] = true;

        int cnt = 0;
        for (int i = 0; i < k; i++) {
            cnt += map[chars[i]] ? 1 : 0;
        }
        int res = cnt;
        for (int i = 1, j = k; j < chars.length; i++, j++) {
            cnt -= map[chars[i - 1]] ? 1 : 0;   //移除左侧
            cnt += map[chars[j]] ? 1 : 0;       //添加右侧
            res = Math.max(res, cnt);
        }
        return res;
    }
}
